package pCloud.acesscontrol;

import java.util.List;

import com.sun.xacml.TargetMatch;
import com.sun.xacml.attr.AttributeDesignator;
import com.sun.xacml.attr.AttributeValue;
import com.sun.xacml.cond.Function;
import com.sun.xacml.cond.FunctionFactory;

public abstract class Match {
	public abstract List getMatchTarget() throws Exception;

	public static TargetMatch createTargetMatch(int type, String functionId,
			AttributeDesignator designator, AttributeValue value) {
		try {
			// get the factory that handles Target functions and get an
			// instance of the right function
			FunctionFactory factory = FunctionFactory.getTargetInstance();
			Function function = factory.createFunction(functionId);

			// create the TargetMatch
			return new TargetMatch(type, function, designator, value);
		} catch (Exception e) {
			// note that in this example, we should never hit this case, but
			// in the real world you need to worry about exceptions, especially
			// from the factory
			return null;
		}
	}
}
